package com.hyjx.framework.service;

import com.hyjx.framework.common.PropertyUtil;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by patrick on 6/22/2017.
 */
public class ConfigManager {

    private static Map<String, String> configMap = new HashMap<String, String>();

    private static JdbcTemplate simpleJdbcTemplate;

    public ConfigManager(DataSource ds){
        simpleJdbcTemplate = new JdbcTemplate(ds);
        List<Map<String, Object>> list = simpleJdbcTemplate.queryForList(PropertyUtil.getGlobalObj().getProperty("cas.jdbc.config.query.sql"));
        if(list == null || list.isEmpty()){
            return;
        }
        for(Map map : list){
            configMap.put(String.valueOf(map.get("CODE")), String.valueOf(map.get("NAME")));
        }
    }
    public ConfigManager(){

    }

    public static String getConfig(String configKey) {
        return configMap.get(configKey);
    }
}
